﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using Zadani09.db.DAO;
using System.Collections.Generic;

namespace Zadani09.db.ODS
{
    [DataObject(true)]
    public class SerieDataObject : DataObject
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Serie> cti(string razeni)
        {
            List<Serie> list = DAOTovarna.instance.getSerieDAO().loadList(0, 0);

            if (list == null) list = new List<Serie>();

            return list;
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Serie> cti_s_vyhledavanim(string razeni, string hledano, string atribut)
        {
            List<Serie> list = cti(razeni);
            List<Serie> vrat = new List<Serie>();

            foreach (Serie jeden in list)
            {
                if (najdi(hledano, jeden, atribut))
                {
                    vrat.Add(jeden);
                }
            }

            return (vrat);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<Serie> ctiJednu(int id)
        {
            List<Serie> list = new List<Serie>();

            Serie serie = DAOTovarna.instance.getSerieDAO().load(id.ToString());

            if (serie != null) list.Add(serie);

            return list;
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public void vloz(Serie data)
        {
            DAOTovarna.instance.getSerieDAO().create(data);
        }

        [DataObjectMethod(DataObjectMethodType.Delete)]
        public void smaz(Serie data)
        {
            DAOTovarna.instance.getSerieDAO().delete(data);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        public void aktualizuj(Serie data)
        {
            DAOTovarna.instance.getSerieDAO().update(data);
        }

    }
}
